#ifndef CAMERA_H
#define CAMERA_H

#include "globals.h"
#include "triangle.h"
#include "ray.h"
#include "scene.h"
#include "configurable.h"
namespace gemren
{
	typedef float float_type;

	class camera : public configurable
	{
	public:
		camera( scene* myscene); 
		virtual void snap(embree::Col3f* img, int width, int height, int spp, bool fast);
		virtual void snap(embree::Col3f* img, int width, int height, int l, int t, int r, int b, int spp, bool fast);
		
		void set_view(const coord& pos, const coord& dir);
		void set_pos(const coord& pos);
		void set_dir(const coord& dir);

		void set_FOV(float fov);
		void set_DOF(float aperture, float focus);//todo by config
		void dir_delta(float dx, float dy, float* newdir = NULL);
		void pos_delta(float dx, float dy, float dz, float* newpos = NULL);

		int shoot_single(int x, int y);
		const std::string& get_onscreen_material_name(int x, int y, int width, int height) const;
		virtual void announce_properties(const std::string& prefix, property_announcer announcer);
	protected:
		virtual err_t set_my_string(std::string& name, const std::string& value);
		virtual err_t set_my_float(std::string& name, const float value);
		inline void rasterizer_data(coord& leftup, coord& dx, coord& dy, const int width, const int height) const;
		static coord local_dir, local_right, local_up;
		random* randoms;
		int maxheight; //size of ^^

		scene* myscene;
		
		float aperture, focus; //depth of field effects
		float_type FOV;
		float move_speed, pitch_speed;
		float rr_min, rr_max;
		coord viewpoint;

		static void scan_line(::size_t tid, void* ptr, ::size_t elt); 
		matrix4x4 look;
	};
	struct camera_data
	{
		//for threads:
		embree::Col3f* img;
		int width, height;
		coord viewpoint;
		coord leftup;
		coord dx, dy;
		scene* myscene;
		random* randoms;
		int spp;
		float aperture, focus;
		float rr_min, rr_max;
		bool fast;
	};
}
#endif